import request from '@/utils/request'

export function page(name,gender,begin,end,page,pageSize) {
  return request({
    url: '/emps?name='+name+'&gender='+gender+'&begin='+begin+'&end='+end+'&page='+page+'&pageSize='+pageSize,
    method: 'get'
  })
}

export function add(emp) {
  return request({
    url: '/emps',
    method: 'post',
    data: emp
  })
}

export function update(dept) {
  return request({
    url: '/emps',
    method: 'put',
    data: dept
  })
}


export function deleteById(id) {
  return request({
    url: '/emps/'+id,
    method: 'delete',
  })
}


export function selectById(id) {
  return request({
    url: '/emps/'+id,
    method: 'get',
  })
}

// 新增导出接口
export function exportEmp() {
  return request({
    url: '/emps/export',
    method: 'get',
    responseType: 'blob'  // 重要：指定响应类型为 blob
  })
}

// 新增导入接口
export function importEmp(file) {
  const formData = new FormData()
  formData.append('file', file)
  return request({
    url: '/emps/import',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}


// 模板下载接口
export function downloadTemplate() {
  return request({
    url: '/emps/import/template',
    method: 'get',
    responseType: 'blob'
  })
}